/*
 * Middleware
 * Copyright (C) 2010/11
 * Riccardo Pulvirenti, Giuseppe Ravidà, Andrea Tino
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANDABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see http://www.gnu.org/licenses
 */

/*!
 * File: data_proxy_factory.cpp
 */

#include "data_proxy_factory.hpp"

using namespace middleware;

//-----------------------------------------------------------------------------
// Constructors and destructor
/* COnstrucotr for sending request */
DataProxyFactory::DataProxyFactory(DataProxyDirection dir,
		std::string ip_w, std::string port_w) {
	this->_proxy = 0;
	if (dir == kSendDataProxy) {
		this->_ip_to_w = ip_w;
		this->_port_to_w = port_w;
		this->_ip_bind_w = "127.0.0.1";
		this->_port_bind_w = "0";
	} else {
		this->_ip_to_w = "127.0.0.1";
		this->_port_to_w = "0";
		this->_ip_bind_w = ip_w;
		this->_port_bind_w = port_w;
	}
}
/* Destructor */
DataProxyFactory::~DataProxyFactory() {
	if (this->_proxy != 0) delete this->_proxy; /* Safe deletion */
}
//-----------------------------------------------------------------------------
// Public members
DataManagerProxy* DataProxyFactory::getProxy() {
	if (this->_proxy != 0) delete this->_proxy; /* Clear first */
	DataProxyConfig proxyconf;
	proxyconf.ip_bind_w = this->_ip_bind_w;
	proxyconf.ip_to_w = this->_ip_to_w;
	proxyconf.port_bind_w = this->_port_bind_w;
	proxyconf.port_to_w = this->_port_to_w;
	this->_proxy = new DataManagerProxy(proxyconf); /* Dynamic alloc */
	return this->_proxy;
}
